home *** CD-ROM | disk | FTP | other *** search
/ Joystick Magazine 1996 May / cd joy 71No13.iso / pc / demos / eurosoc / source / euro_dsk.cpp < prev    next >
C/C++ Source or Header  |  1996-03-14  |  4KB  |  169 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. #include "eurodefs.h"
  6. #include "euro_fxd.h"
  7. #include "mallocx.h"
  8. #include "euro_sym.h"
  9. #include "euro_def.h"
  10. #include "euro_var.h"
  11. #include "euro.equ"
  12.  
  13.  
  14.     FILE         *fp2;            // symbol creation file.
  15.  
  16. //********************************************************************************************************************************
  17.  
  18. signed int ReadLine( FILE *fp, char *buf )
  19.     {
  20.     signed char c;
  21.     buf[0]    = 0;
  22.     int nc = 0;
  23.  
  24.     while( (( (c=fgetc(fp)) !=LF)&&(c!=EOF)))
  25.         {
  26.  
  27.         if (c==EOF || c==LF || c==255)
  28.             *(buf++)=0;
  29.         else
  30.             {
  31.                 *(buf++)=c;
  32.                 nc++;
  33.             }
  34.         }
  35.         if(c==EOF) nc=-1;
  36.         return(nc);
  37.     }
  38.  
  39. //********************************************************************************************************************************
  40.  
  41. void    ReadDataOffsetFile( char *filename )
  42.     {
  43.     FILE *fp1;
  44.  
  45.     fp1=fopen( filename, "rb" );
  46.  
  47.     if ( fp1 != NULL )
  48.         {
  49.             fread( Offset_table, sizeof(BYTE), 512*4, fp1 );
  50.             fclose(fp1);
  51.                   printf("˛ Data Offset file loaded.\n");
  52.         }
  53.     else
  54.                printf("˛ Error loading Data Offset file.\n");
  55.     }
  56.  
  57.  
  58. //********************************************************************************************************************************
  59.  
  60. void    ReadData( int file, char *filename, BYTE *buffer )
  61.     {
  62.         long    seek_pos, file_size, len;
  63.         FILE    *fd;
  64.         fd = fopen( filename, "rb" );
  65.  
  66.         if(fd!=NULL)
  67.         {
  68.             seek_pos    =    Offset_table[file/8].offset;
  69.             file_size    =    Offset_table[file/8].size;
  70.             fseek( fd, seek_pos , SEEK_SET );    
  71.             fread( buffer, sizeof(BYTE), file_size, fd );
  72.         }    
  73.         else
  74.                    printf("˛ Error loading from Datafile.\n");
  75.  
  76.         fclose( fd );
  77.     }
  78.  
  79. //********************************************************************************************************************************
  80.  
  81. void    LoadTexturePage( int file, char *filename, unsigned char Page, texture_info *texture )
  82.     {
  83.         if ( Page < TexturePagesAvailable )
  84.  
  85.                   ReadData( file, filename, texture->page_start + (texture->page_width*texture->page_height*Page) );
  86.         
  87.         else
  88.  
  89.             printf("ERROR... trying to access texture page: %d, when only %d page(s) exist\n", 
  90.                 Page, TexturePagesAvailable);
  91.     }
  92.  
  93. //********************************************************************************************************************************
  94.  
  95. void    LoadPalette( int file, char *filename, int offset )
  96.     {
  97.               ReadData( file, filename, &PaletteBuffer[ (offset*3) ] );
  98.     }
  99.  
  100. //********************************************************************************************************************************
  101.  
  102. void    LoadTactics( int tactic, char *filename, int *buffer)
  103.     {
  104.               ReadData( (tactic*8)+TAC_TAC_316, filename, (BYTE *)buffer );
  105.     }
  106.  
  107. //********************************************************************************************************************************
  108.  
  109. void    SaveGameData(char *filename)
  110.     {
  111.         FILE *fp=fopen(filename,"wb");
  112.  
  113.         if(fp!=NULL)
  114.         {
  115.             fwrite(SquadInfo,     sizeof(char),         16*20, fp);
  116.             fwrite(FormationInfo,     sizeof(char),         16,    fp);
  117.             fwrite(GroupDrawInfo,     sizeof(char),         16,    fp);
  118.             fwrite(LeagueTable,     sizeof(League_info),     16,    fp);
  119.             fwrite(&NoOfSubs,     sizeof(char),         1,     fp);
  120.             fwrite(&WinPts,        sizeof(char),         1,     fp);
  121.             fwrite(&DrawPts,     sizeof(char),         1,     fp);
  122.             fwrite(&MatchNumber,     sizeof(MatchNumber),     1,     fp);
  123.             fclose(fp);                        
  124.         }
  125.  
  126.     }
  127.  
  128. //********************************************************************************************************************************
  129.  
  130. void    LoadGameData(char *filename)
  131.     {
  132.         FILE *fp=fopen(filename,"rb");
  133.  
  134.         if(fp!=NULL)
  135.         {
  136.             fread(SquadInfo,     sizeof(char),         16*20, fp);
  137.             fread(FormationInfo,     sizeof(char),         16,    fp);
  138.             fread(GroupDrawInfo,     sizeof(char),         16,    fp);
  139.             fread(LeagueTable,     sizeof(League_info),     16,    fp);
  140.             fread(&NoOfSubs,     sizeof(char),         1,     fp);
  141.             fread(&WinPts,         sizeof(char),         1,     fp);
  142.             fread(&DrawPts,     sizeof(char),         1,     fp);
  143.             fread(&MatchNumber,     sizeof(MatchNumber),     1,     fp);
  144.             fclose(fp);                        
  145.         }            
  146.  
  147.     }
  148.  
  149. //********************************************************************************************************************************
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.